<?php
if ( ! defined( 'IN_IPB' ) )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
	exit();
}

class component_public
{
	var $ipsclass;
	
	function run_component()
	{
		$this->ipsclass->code = ob_get_contents();ob_end_clean();
		
		// Is it installed yet?
		if(!isset($this->ipsclass->vars['market_on']) || !isset($this->ipsclass->vars['market_members_field']))
		{
			$this->ipsclass->lang['not_installed'] = "This component has not been installed yet.";
			$this->ipsclass->Error(array('MSG'=>'not_installed'));
		}
		
		$this->ipsclass->nav = array();
		
		$this->ipsclass->market_class->base_url = $this->ipsclass->base_url."autocom=market&amp;";
		$this->ipsclass->market_class->js_base_url = $this->ipsclass->base_url."autocom=market&";
		
		$this->ipsclass->load_template('skin_market');
		$this->ipsclass->load_language('lang_market');
		
		// Root admin eh
		if($this->ipsclass->member['mgroup'] == $this->ipsclass->vars['admin_group'])
		{
			$this->ipsclass->vars['market_on'] = 1;
			$this->ipsclass->member['g_market_view'] = 1;
			$this->ipsclass->member['g_market_use'] = 1;
			$this->ipsclass->member['_market_access'] = -1;
		}
		// Nope, I'm a guest to this board
		elseif($this->ipsclass->member['id'] == 0 || $this->ipsclass->member['mgroup'] == $this->ipsclass->vars['guest_group'])
		{
			$this->ipsclass->member['id'] = 0;
			$this->ipsclass->member['mgroup'] = $this->ipsclass->vars['guest_group'];
			$this->ipsclass->member['g_market_view'] = $this->ipsclass->vars['market_guests'];
			$this->ipsclass->member['g_market_use'] = 0;
			$this->ipsclass->member['_market_access'] = -1;
		}
		
		if($this->ipsclass->member['id'])
		{
			if(!isset($this->ipsclass->member['market_access']) || !isset($this->ipsclass->member[$this->ipsclass->vars['market_members_field']]))
			{
				$this->ipsclass->member = array_merge($this->ipsclass->DB->build_and_exec_query(array('select'=>'*','from'=>'members','where'=>"id=".$this->ipsclass->member['id'])),$this->ipsclass->member);
			}
		}
		
		$this->ipsclass->member['market_access'] = $this->ipsclass->member['_market_access'] ? $this->ipsclass->member['_market_access'] : $this->ipsclass->member['market_access'];
		$this->ipsclass->member['market_deduct'] = ( 100 - $this->ipsclass->member['g_market_discount'] ) / 100;
		
		if($this->ipsclass->member['id'] && $this->ipsclass->member['market_access'] != -1)
		{
			$this->ipsclass->member['g_market_view'] = $this->ipsclass->member['market_access'];
		}
		
		is_null(@call_user_func(array(&$this->ipsclass->print,'_check_ips_report'))) ? '' : exit();
		// Check if ibMarket is offline
		if(!$this->ipsclass->vars['market_on'])
		{
			$this->ipsclass->Error(array('MSG'=>'market_offline'));
		}
		// Check if guests is allowed
		if(!$this->ipsclass->vars['market_guests'] && $this->ipsclass->member['mgroup'] == $this->ipsclass->vars['guest_group'])
		{
			$this->ipsclass->Error(array('MSG'=>'market_noguest'));
		}
		// Check if able to view the market
		if(!$this->ipsclass->member['g_market_view'])
		{
			$this->ipsclass->Error(array('MSG'=>'market_noview'));
		}
		
		if($this->ipsclass->member['id'])
		{
			$delete = array();
			$this->ipsclass->DB->build_query(array('select'=>'*','from'=>'market_inventory','where'=>"member_id=".$this->ipsclass->member['id']));
			$q = $this->ipsclass->DB->exec_query();
			while($item = $this->ipsclass->DB->fetch_row($q))
			{
				if(!is_array($this->ipsclass->cache['market_items'][$item['item']]))
				{
					$delete[] = $item['i_id'];
					continue;
				}
				if($item['expired'] && $item['expired'] < time())
				{
					$delete[] = $item['i_id'];
					continue;
				}
				$this->ipsclass->market_class->inventory[$item['item']][$item['i_id']] = $item;
				$this->ipsclass->market_class->inventory_id[$item['i_id']] = $item;
			}
			if(count($delete))
			{
				$this->ipsclass->DB->do_delete('market_inventory',"i_id IN (".implode(', ',$delete).")");
			}
		}
		else
		{
			$this->ipsclass->member[$this->ipsclass->vars['market_members_field']] = 0;
		}
		$this->ipsclass->member['money_format'] = $this->ipsclass->numbers->format_currency($this->ipsclass->member[$this->ipsclass->vars['market_members_field']]);
		
		$this->ipsclass->market_class->load_class();
		$this->ipsclass->market_class->build_menu();
		
		if($this->ipsclass->member['g_market_use'])
		{
			$redirect = array(
								'home' => 'inventory',
								'inventory' => 'inventory',
								'shop' => 'categories',
								'checkout' => 'buy_items',
								'buy' => 'buy_items',
								'item' => 'process_item',
								'receipt' => 'receipts',
								'fee' => 'logs',
								'reward' => 'logs',
								'wages' => 'wages',
								'plugin' => 'plugin',
								'member' => 'view_member',
							);
		}
		else
		{
			$redirect = array(
								'home' => 'categories',
								'shop' => 'categories',
								'plugin' => 'plugin',
								'member' => 'view_member',
							);
		}
		
		if($this->ipsclass->input['plugin'])
		{
			$this->ipsclass->input['CODE'] = 'plugin';
		}
		
		if(!isset($redirect[$this->ipsclass->input['CODE']]))
		{
			$this->ipsclass->input['CODE'] = 'home';
		}
		eval(base64_decode('cmVxdWlyZV9vbmNlKFJPT1RfUEFUSC4nc291cmNlcy9tYXJrZXQvcHVibGljLycuJHJlZGlyZWN0WyR0aGlzLT5pcHNjbGFzcy0+aW5wdXRbJ0NPREUnXV0uJy5waHAnKTskY29uc3RydWN0b3I9JHJlZGlyZWN0WyR0aGlzLT5pcHNjbGFzcy0+aW5wdXRbJ0NPREUnXV07JHJ1bm1lYWdhaW49bmV3ICRjb25zdHJ1Y3RvcjtpZighaW5fYXJyYXkoJ19jaGVja19pcHNfcmVwb3J0JyxnZXRfY2xhc3NfbWV0aG9kcygnZGlzcGxheScpKSl7ZXhpdCgpO30kcnVubWVhZ2Fpbi0+aXBzY2xhc3MgPSYgJHRoaXMtPmlwc2NsYXNzO2RlZmluZSgnSUJNQVJLRVQnLDUpOyRydW5tZWFnYWluLT5hdXRvX3J1bigpOw=='));
		// Empty page
		$this->ipsclass->market_class->output($this->ipsclass->output,$this->ipsclass->nav,$this->ipsclass->subtitle);
	}
}

ob_start();
?>aWYoIW1ldGhvZF9leGlzdHMoJHRoaXMtPmlwc2NsYXNzLT5wcmludCwnX2NoZWNrX2lwc19yZXBvcnQnKSl7JHRoaXMtPmlwc2NsYXNzLT5wcmludC0+ZG9fb3V0cHV0KGFycmF5KCkpO31kZWZpbmUoJ0dPT0QnLDEpOw==